package edu.nf.bs.dao.impl;

import edu.nf.bs.dao.OrderInfoMapper;
import edu.nf.bs.entity.DeliveryMan;
import edu.nf.bs.entity.OrderInfo;
import edu.nf.bs.util.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;
import java.util.List;

public class OrderInfoMapperImpl implements OrderInfoMapper {


    /**
     * 获取今日收入
     * @return
     */
    @Override
    public Double getPrice() {
        SqlSession sqlSession = MyBatisUtils.getSqlSession(true);
        OrderInfoMapper mapper = sqlSession.getMapper(OrderInfoMapper.class);
        Double price = mapper.getPrice();
        sqlSession.close();
        return price;
    }

    /**
     * 获取这个月收入
     * @return
     */
    @Override
    public Double getMysqlDate() {
        SqlSession sqlSession = MyBatisUtils.getSqlSession(true);
        OrderInfoMapper mapper = sqlSession.getMapper(OrderInfoMapper.class);
        Double mysqlDate = mapper.getMysqlDate();


        sqlSession.close();
        return mysqlDate;
    }

    /**
     * 查询当天的订单数量
     * @return
     */
    @Override
    public Integer getMonthOrder() {
        SqlSession sqlSession = MyBatisUtils.getSqlSession(true);
        OrderInfoMapper mapper = sqlSession.getMapper(OrderInfoMapper.class);
        Integer monthOrder = mapper.getMonthOrder();
        sqlSession.close();
        return monthOrder;
    }
    /**
     * 获取一个月的订单数量
     * @return
     */
    @Override
    public Integer getMonthOrders() {
        SqlSession sqlSession = MyBatisUtils.getSqlSession(true);
        OrderInfoMapper mapper = sqlSession.getMapper(OrderInfoMapper.class);
        Integer monthOrders = mapper.getMonthOrders();

        sqlSession.close();
        return monthOrders;
    }
    /**
     * 查询派单量最多的一个快递员
     * @return
     */
    @Override
    public DeliveryMan getOrderMax() {
        SqlSession sqlSession = MyBatisUtils.getSqlSession(true);
        OrderInfoMapper mapper = sqlSession.getMapper(OrderInfoMapper.class);
        DeliveryMan orderMax = mapper.getOrderMax();
        sqlSession.close();
        return orderMax;
    }
    /**
     * 订单查询
     * @param orderId 查询条件，根据省份查询
     * @param pageNum 当前页 @Param 注解的 value 值必须是 pageNum
     * @param pageSize 每页显示记录数 @Param 注解的 value 值必须是 pageSize
     * @return
     */
    @Override
    public List<OrderInfo> listOrder(String orderId, Integer pageNum, Integer pageSize) {
        SqlSession sqlSession = MyBatisUtils.getSqlSession(true);
        OrderInfoMapper mapper = sqlSession.getMapper(OrderInfoMapper.class);
        List<OrderInfo> orderInfos = mapper.listOrder(orderId, pageNum, pageSize);
        sqlSession.close();
        return orderInfos;
    }
    /**
     * 查询12个月份的收入
     * @return
     */
    @Override
    public Double[] getYearPrice() {
        SqlSession sqlSession = MyBatisUtils.getSqlSession(true);
        OrderInfoMapper mapper = sqlSession.getMapper(OrderInfoMapper.class);
        Double[] yearPrice = mapper.getYearPrice();
        sqlSession.close();
        return  yearPrice;
    }

    @Override
    public Integer updateOrderStatus(String logisticsId) {
        SqlSession sqlSession = MyBatisUtils.getSqlSession(true);
        OrderInfoMapper mapper = sqlSession.getMapper(OrderInfoMapper.class);
        Integer integer = mapper.updateOrderStatus(logisticsId);
        sqlSession.close();
        return integer;
    }

    /**
     * 添加订单
     * @param orderInfo
     * @return
     */
    @Override
    public Integer addOrderInfo(OrderInfo orderInfo) {
        SqlSession sqlSession = MyBatisUtils.getSqlSession(true);
        OrderInfoMapper mapper = sqlSession.getMapper(OrderInfoMapper.class);
        Integer integer = mapper.addOrderInfo(orderInfo);
        sqlSession.close();
        return integer;
    }

    @Override
    public Integer updateOrderInfo(String orderId, float orderPrice) {
        SqlSession sqlSession = MyBatisUtils.getSqlSession(true);
        OrderInfoMapper mapper = sqlSession.getMapper(OrderInfoMapper.class);
        Integer integer = mapper.updateOrderInfo(orderId, orderPrice);
        sqlSession.close();
        return integer;
    }

    @Override
    public Integer updateLogistics(String expressId, String logisticsId) {
        SqlSession sqlSession = MyBatisUtils.getSqlSession(true);
        OrderInfoMapper mapper = sqlSession.getMapper(OrderInfoMapper.class);
        Integer integer = mapper.updateLogistics(expressId, logisticsId);
        sqlSession.close();
        return integer;
    }

    @Override
    public OrderInfo queryLogistics(String expressId) {
        SqlSession sqlSession = MyBatisUtils.getSqlSession(true);
        OrderInfoMapper mapper = sqlSession.getMapper(OrderInfoMapper.class);
        OrderInfo orderInfo = mapper.queryLogistics(expressId);
        sqlSession.close();
        return orderInfo;
    }

    @Override
    public List<OrderInfo> queryOrderInfo(String userId,Integer pageNum,Integer pageSize) {
        SqlSession sqlSession = MyBatisUtils.getSqlSession(true);
        OrderInfoMapper mapper = sqlSession.getMapper(OrderInfoMapper.class);
        List<OrderInfo> orderInfos = mapper.queryOrderInfo(userId, pageNum, pageSize);
        sqlSession.close();
        return orderInfos;
    }

}
